
package com.example.aes;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import java.io.UnsupportedEncodingException;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.click).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String key = AESUtils.generateSecureRandom();

                String content = "nihao";
                try {
                    String encode = AESUtils.encryptCbc(content.getBytes("UTF-8"), key);
                    Toast.makeText(MainActivity.this, key + "解码：" +
                            "" + AESUtils.decodeCbc(encode, key), Toast.LENGTH_LONG).show();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
        });


    }
}